// Copyright 2022 jeff.li. and/or its affiliates.

#include <tbir/runtime/env_time.h>

#include <ctime>

namespace tbir::runtime {

    class PosixEnvTime : public EnvTime {
    public:
        PosixEnvTime() = default;

        uint64_t NowNanos() const override {
            struct timespec ts;
            clock_gettime(CLOCK_REALTIME, &ts);
            return (static_cast<uint64_t>(ts.tv_sec) * kSecondsToNanos + static_cast<uint64_t>(ts.tv_nsec));
        }
    };

    EnvTime *EnvTime::Default() {
        static EnvTime *default_env_time = new PosixEnvTime;
        return default_env_time;
    }

}  // namespace tbir::runtime
